//
// Created by Jisam on 2024/7/15.
//
#include <bits/stdc++.h>
#define PSI pair<string,int>
#define PII pair<int,int>
#define VVI vector<vector<int>>
#define VI vector<int>
#define VS vector<string>
#define i64 long long

using namespace std;

const int N = 1e5 + 5;
int ans;
void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int slow = -1;
    int fast = 0;
    int cnt0 = 0;
    int cnt1 = 0;
    int f = 0;
    if(s[0] == '0'){
        s= "1" + s + "1";
        f = 1;
    }

    for(int i = 0 ; i < n ; i ++){
        if(s[i] == '1') cnt1 ++;
    }
    while(slow <= fast){
        if(s[fast] == '1') {
//            cout << slow <<" "<< fast <<"      \n";

            if(slow>=0 && fast >= 0 && slow <= n && fast <= n) {
                cnt0 ++;
            }
            slow = fast;
            fast = slow;
            fast ++;
            continue;
        }
        else  {
            fast ++;
        }

        if(fast >n){
            fast ++ ;
            break;
        }
    }
//    cout << cnt0 <<" "<< cnt1 <<" \n";
    if(f){
        if(cnt1 <= cnt0 +2 ){
            cout << "NO";
        }else {
            cout <<  "YES";
        }
    }else{
        if(cnt1 <= cnt0  ){
            cout << "NO";
        }else {
            cout <<  "YES";
        }
    }

    cout <<"\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;cin >> T;while(T --)
        solve();
    return 0;
}